home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / ctltcviewer.ctl < prev    next >
Encoding:
Text File  |  2001-10-16  |  5.6 KB  |  242 lines

  1. VERSION 5.00
  2. Begin VB.UserControl ctlTcViewer 
  3.    BorderStyle     =   1  'Fixed Single
  4.    ClientHeight    =   4320
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   4710
  8.    ControlContainer=   -1  'True
  9.    KeyPreview      =   -1  'True
  10.    ScaleHeight     =   288
  11.    ScaleMode       =   3  'Pixel
  12.    ScaleWidth      =   314
  13. End
  14. Attribute VB_Name = "ctlTcViewer"
  15. Attribute VB_GlobalNameSpace = False
  16. Attribute VB_Creatable = True
  17. Attribute VB_PredeclaredId = False
  18. Attribute VB_Exposed = True
  19. '******************************************************************'
  20. '*                                                                *'
  21. '*                      TurboCAD for Windows                      *'
  22. '*                   Copyright (c) 1993 - 2001                    *'
  23. '*             International Microcomputer Software, Inc.         *'
  24. '*                            (IMSI)                              *'
  25. '*                      All rights reserved.                      *'
  26. '*                                                                *'
  27. '******************************************************************'
  28.  
  29. Option Explicit
  30.  
  31. Public Event ClickGraphic(gxGr As Graphic, dist As Double)
  32.  
  33. Dim gxDwg As Drawing
  34. Dim gxVw  As View
  35. Dim bAttached As Boolean
  36. Dim dblAperture As Double
  37. Dim bUpdate As Boolean
  38.  
  39. Public Sub Refresh()
  40.     Cls
  41.     If (bAttached) Then
  42.         If (bUpdate) Then
  43.             gxVw.Refresh
  44.         End If
  45.     End If
  46. End Sub
  47.  
  48. Public Sub Scroll(dy As Long, dx As Long)
  49.     If (bAttached) Then
  50.         On Error GoTo VwZoom
  51.          gxVw.Camera.Slide gxVw.ViewHeight() * dy / 10, gxVw.ViewWidth() * dx / 10
  52.         Exit Sub
  53. VwZoom:
  54.         Dim yTop As Double
  55.         Dim xLeft As Double
  56.         
  57.         On Error GoTo Err
  58.         
  59.         xLeft = gxVw.ViewLeft + gxVw.ViewWidth() * dx / 10
  60.         yTop = gxVw.ViewTop - gxVw.ViewHeight() * dy / 10
  61.         
  62.         gxVw.Update = False
  63.         
  64.         gxVw.ViewLeft = xLeft
  65.         gxVw.ViewTop = yTop
  66.     
  67.     End If
  68. Err:
  69. End Sub
  70.  
  71. Public Sub Zoom(factor As Double)
  72.  
  73.     If (bAttached) Then
  74.         If (factor <> 0) Then
  75.             On Error GoTo VwZoom
  76.             gxVw.Camera.Zoom factor
  77.             Exit Sub
  78.             
  79.         Else
  80.             gxVw.ZoomToExtents
  81.         End If
  82.     End If
  83.     Exit Sub
  84. VwZoom:
  85.         Dim xC As Double
  86.         Dim yC As Double
  87.         
  88.         Dim w As Double
  89.         Dim h As Double
  90.     
  91.         On Error GoTo Err
  92.         w = gxVw.ViewWidth
  93.         h = gxVw.ViewHeight
  94.     
  95.         xC = gxVw.ViewLeft + w / 2
  96.         yC = gxVw.ViewTop - h / 2
  97.     
  98.         w = w * factor
  99.         h = h * factor
  100.     
  101.         gxVw.Update = False
  102.         
  103.         gxVw.ViewLeft = xC - w / 2
  104.         gxVw.ViewTop = yC + h / 2
  105.     
  106.         gxVw.ViewWidth = w
  107.         gxVw.ViewHeight = h
  108. Err:
  109. End Sub
  110.  
  111. Public Function Detach() As Boolean
  112.     
  113.     On Error Resume Next
  114.     If (Not gxVw Is Nothing) Then
  115.         gxVw.Delete
  116.         Set gxVw = Nothing
  117.     End If
  118.     
  119.     If (Not gxDwg Is Nothing) Then
  120.         Set gxDwg = Nothing
  121.     End If
  122.     bAttached = False
  123.     
  124.     Detach = bAttached
  125.     
  126. End Function
  127. Public Function Attach(objDwg As Object) As Boolean
  128.  
  129.     Dim gxProps As Properties
  130.     Dim gxProp As Property
  131.     
  132.     On Error GoTo Err
  133.     
  134.     Detach
  135.     
  136.     Set gxDwg = objDwg
  137.     Set gxProps = gxDwg.Application.Properties
  138.     Set gxProp = gxProps("Aperture")
  139.     
  140.     dblAperture = gxProp
  141.     
  142.     Set gxProp = Nothing
  143.     Set gxProps = Nothing
  144.     
  145.     Set gxVw = gxDwg.Views.Add(hWnd)
  146.     gxVw.ZoomToExtents
  147.     
  148.     bAttached = True
  149.  
  150. Err:
  151.     If (Err <> 0) Then
  152.         MsgBox Err.Description
  153.     End If
  154.     
  155.     Attach = bAttached
  156. End Function
  157.  
  158. Private Sub UserControl_Initialize()
  159.     bAttached = False
  160.     bUpdate = True
  161.     Set gxVw = Nothing
  162.     Set gxDwg = Nothing
  163.     dblAperture = 1
  164. End Sub
  165.  
  166. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  167.  
  168.     Dim xVw As Double
  169.     Dim yVw As Double
  170.     Dim xW As Double
  171.     Dim yW As Double
  172.     Dim zW As Double
  173.     
  174.     Dim gxPickRes As PickResult
  175.     Dim gxPickEntry As PickEntry
  176.     Dim cnt As Long
  177.     Dim ind As Long
  178.     
  179.     If (bAttached) Then
  180.     
  181.         gxVw.ScreenToView X, Y, xVw, yVw
  182.         
  183.         Set gxPickRes = gxVw.PickPoint(xVw, yVw, dblAperture, True, True, True, True, True, False)
  184.     
  185.         cnt = gxPickRes.Count - 1
  186.         For ind = 0 To cnt
  187.             Set gxPickEntry = gxPickRes.Item(ind)
  188.             RaiseEvent ClickGraphic(gxPickEntry.Graphic, gxPickEntry.Distance)
  189.         Next ind
  190.     
  191.     End If
  192.  
  193.     Set gxPickEntry = Nothing
  194.     Set gxPickRes = Nothing
  195.  
  196.     Refresh
  197. End Sub
  198.  
  199. Private Sub UserControl_Paint()
  200.     If (bAttached And bUpdate) Then
  201.         On Error Resume Next
  202.         gxVw.Refresh
  203.     End If
  204. End Sub
  205.  
  206. Private Sub UserControl_Terminate()
  207.     
  208.     Detach
  209.  
  210. End Sub
  211.  
  212. Public Property Get ViewSpace() As Variant
  213.     If (Not gxVw Is Nothing) Then
  214.         ViewSpace = gxVw.SpaceMode
  215.     End If
  216. End Property
  217.  
  218. Public Property Let ViewSpace(ByVal vNewValue As Variant)
  219.     Dim bSpace As ImsiSpaceModeType
  220.     bSpace = vNewValue
  221.     If (Not gxVw Is Nothing) Then
  222.         gxVw.SpaceMode = bSpace
  223.         gxVw.Refresh
  224.     End If
  225. End Property
  226.  
  227. Public Property Get Aperture() As Variant
  228.     Aperture = dblAperture
  229. End Property
  230.  
  231. Public Property Let Aperture(ByVal vNewValue As Variant)
  232.     dblAperture = vNewValue
  233. End Property
  234.  
  235. Public Property Get Update() As Variant
  236.     Update = bUpdate
  237. End Property
  238.  
  239. Public Property Let Update(ByVal vNewValue As Variant)
  240.     bUpdate = vNewValue
  241. End Property
  242.